package com.mccken.eshop.common.exception;

import java.text.MessageFormat;

import lombok.Data;

/**
 * 基础自定义业务异常
 * 
 * 
 * @program: mccken-collect
 * @description:
 * @author: mccken
 * @create: 2022-08-25 23:02
 **/
@Data
public class BaseBizException extends RuntimeException{

	/**
	 * 默认错误码
	 */
	private static final String DEFAULT_ERROR_CODE = "-1";
	
	private String errorCode;
	
	private String errorMsg;
	
	public BaseBizException(String errorMsg){
		super(errorMsg);
		this.errorCode = DEFAULT_ERROR_CODE;
		this.errorMsg = errorMsg;
	}
	
	public BaseBizException(String errorCode, String errorMsg){
		super(errorMsg);
		this.errorMsg = errorMsg;
		this.errorCode = errorCode;
	}
	
	public BaseBizException(BaseErrorCodeEnum baseErrorCodeEnum) {
		super(baseErrorCodeEnum.getErrorMsg());
		this.errorMsg = baseErrorCodeEnum.getErrorMsg();
		this.errorCode = baseErrorCodeEnum.getErrorCode();
	}
	
	public BaseBizException(String errorCode, String errorMsg, Object... arguments){
		super(MessageFormat.format(errorMsg , arguments));
		this.errorMsg = errorMsg;
		this.errorCode = errorCode;
	}
	
	public BaseBizException(BaseErrorCodeEnum baseErrorCodeEnum, Object... arguments) {
		super(MessageFormat.format(baseErrorCodeEnum.getErrorMsg(), arguments));
		this.errorMsg = baseErrorCodeEnum.getErrorMsg();
		this.errorCode = baseErrorCodeEnum.getErrorCode();
	}
}
